package com.labi.designpattern.controller;


import com.labi.designpattern.enums.OrderEvent;
import com.labi.designpattern.enums.OrderState;
import com.labi.designpattern.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.statemachine.state.State;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

    private final OrderService orderService;

    @Autowired
    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @GetMapping("/create-order")
    public String createOrder() {
        String orderId = orderService.createOrder();
        return "Order created>>  " + orderId;
    }

    @GetMapping("/check")
    public String checkOrder(String orderId) {
        orderService.checkOrder(orderId);
        return "Order paid";
    }
    @GetMapping("/pay-order")
    public String payOrder(String orderid) {
        orderService.payOrder(orderid);
        return "Order paid";
    }


    @GetMapping("/complete-order")
    public String completeOrder(String orderId) {
        orderService.completeOrder(orderId);
        return "Order completed";
    }

    @GetMapping("/order-status")
    public String getOrderStatus() {
//        State<OrderState, OrderEvent> currentState = orderService.getCurrentState(orderId);
        return orderService.getOrders().toString();
//        return "Current order status: " + currentState.getId();
    }
}
